var api = require("../../../../api.js"),
  QQMapWX = require("../../../../qqmap-wx.js"),
  app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentItemId: "1",
    dataArr: [
      {
        
      },
      {
        id: 1,
        wareArr: [
          {
            id: 0,
            old_order_no: 123,
            goodsname: "商品",
            price: "10.0",
            myadds: "地址",
            laiyuan: "UU跑腿",
            time: "2分钟前"
          }
        ]
      }
    ]
  },
  onLoad: function (options) {
    var that = this;
    
    that.setData({
      head: wx.getStorageSync('head'),
      icons: wx.getStorageSync('site') + '/addons/sd_liferuning/tp/public/uploads/background',
    })
    app.request({
      url: api.default.HeJiangOrder,
      data: {
        uid: wx.getStorageSync('uid'),
        bid: wx.getStorageSync('bid')
      },
      success: function (res) {
        console.log('订单', res);
        that.setData({
          dataArr: res
        });
      }
    })
  },
  selectSwiper: function (e) {
    var that = this;
    var val = e.currentTarget.dataset.listid;
    console.log(val)
    that.setData({
      currentItemId: val
    });
  },
  changeSwiper: function (e) {
    var that = this;
    var val = e.detail.currentItemId;
    that.setData({
      currentItemId: val
    });
  },
  refreshData: function(e){
    let _this = this;
    let _id = e.currentTarget.dataset.id;
    let _dataArr = _this.data.dataArr;

    _dataArr.forEach(function(item,index){
      if (item.id == _id){
        let dataArr = _this.sendRequest(_id);
        if (dataArr != -1){
          item.wareArr = item.wareArr.concat(dataArr);
        }
      }
    });
    
    _this.setData({
      dataArr: _dataArr
    });
  },
  pushOrder: function(e){
    let _this = this;
    let _id = e.currentTarget.dataset.id;
    let _type = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '/sd_liferuning/pages/constmer/largess/index?type_id=' + _id + '&type=' + _type,
    })
  },
  /**
   * 通过ID进行数据查询
   * @param id
   * @return Array 为空返回-1
   */
  sendRequest: function(id){
    let _id = id;
    let dataArr = -1;
    // TODO 进行请求
    dataArr = [
      // {
      //   id: 0,
      //   orderNumber: 123,
      //   wareName: "商品",
      //   warePrice: "10.0",
      //   address: "地址",
      //   source: "UU跑腿",
      //   pushTime: "299分钟前"
      // }
      ];
    return dataArr;
  }
})